﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EmotionRecognitionMessages;
using EmotionRecognitionEntities;
using System.Windows.Forms.DataVisualization.Charting;

namespace EmotionRecognitionGui
{
    public partial class Statistics : BasicForm
    {//

        BasicForm lastGui;

        public Statistics():base()
        {
            try
            {
                InitializeComponent();
                CreateChart();
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.ToString());
            }
             
        }

        Messages msg = new Messages();
        private void  CreateChart()
        {

             
           this.retrievalChart.Series["Data"].Points[0].LegendText = "User Accepts Retrieval Answer";
           this.retrievalChart.Series["Data"].Points[1].LegendText = "User Rejects Retrieval Answer";  
           Title RetrievalTitle = new Title("Retrieval", Docking.Top, new Font("Verdana", 12), Color.Black);
          this.retrievalChart.Titles.Add(RetrievalTitle);
          this.secondRoundChart.Series["Data"].Points[0].LegendText = "User Accepts Retrieval Answer";
          this.secondRoundChart.Series["Data"].Points[1].LegendText = "User Rejects Retrieval Answer";
          Title improvedRetrievalTitle = new Title("Improved Retrieval", Docking.Top, new Font("Verdana", 12), Color.Black);
          this.secondRoundChart.Titles.Add(improvedRetrievalTitle);
          this.afterRefinmentChart.Series["Data"].Points[0].LegendText = "User Accepts Retrieval Answer";
          this.afterRefinmentChart.Series["Data"].Points[1].LegendText = "User Rejects Retrieval Answer";
          Title afterRefinementlTitle = new Title("Refinement Retrieval", Docking.Top, new Font("Verdana", 12), Color.Black);
          this.afterRefinmentChart.Titles.Add(afterRefinementlTitle);
               
                    
                
            
          
        }

        public void LoadChart()
        {
             msg = new Messages();
            ReplyMsg reply = msg.GetretrievalCorrectAnswer();

            if (this.retrievalChart.Series["Data"].Points.Count != 0)
            {
                this.retrievalChart.Series["Data"].Points[0].SetValueY((int)reply.ParamArray[0]);
                this.retrievalChart.Series["Data"].Points[1].SetValueY((int)reply.ParamArray[1]);
                this.retrievalChart.Series["Data"].Points.Invalidate();
            }
         
             
            if (this.secondRoundChart.Series["Data"].Points.Count != 0)
            {
                this.secondRoundChart.Series["Data"].Points[0].SetValueY((int)reply.ParamArray[2]);
                this.secondRoundChart.Series["Data"].Points[1].SetValueY((int)reply.ParamArray[3]);
                this.secondRoundChart.Series["Data"].Points.Invalidate();
            }


            if (this.afterRefinmentChart.Series["Data"].Points.Count != 0)
            {
                this.afterRefinmentChart.Series["Data"].Points[0].SetValueY((int)reply.ParamArray[4]);
                this.afterRefinmentChart.Series["Data"].Points[1].SetValueY((int)reply.ParamArray[5]);
                this.afterRefinmentChart.Series["Data"].Points.Invalidate();
            }

        

        }
          
        private void button1_Click(object sender, EventArgs e)
        {
            GuiManager.Instance.SwitchForms(this, GuiManager.Instance.mainMenuExpertGui);
        }

        private void buttonBack_Click_1(object sender, EventArgs e)
        {
            GuiManager.Instance.SwitchForms(this, lastGui);
            

        }

        private void resetBasicButton_Click(object sender, EventArgs e)
        {
            msg.ResetStatistics(StatisticsType.Basic);

            LoadChart();
       
           

        }

        private void resetSecondIndexButton_Click(object sender, EventArgs e)
        {
            msg.ResetStatistics(StatisticsType.SecondIndex);
           
            LoadChart();

        }

        private void afterRefinementResetButton_Click(object sender, EventArgs e)
        {
            msg.ResetStatistics(StatisticsType.Refinement);
            LoadChart();
        }

        public void EnterStatistics(BasicForm lastGui)
        {
            this.lastGui = lastGui;
            this.Show();
            LoadChart();

        }
         
 
    }
}
